import { Controller, Post, Body } from '@nestjs/common';
import { AuthService } from './auth.service';
import { Public } from './public.decorator';
import { success } from 'src/utils';

/**
 * 认证控制器
 * 处理用户认证相关的请求，包括登录和微信登录
 */
@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) { }

  /**
   * 用户登录接口
   * @param username - 用户名
   * @param password - 密码
   * @returns 登录成功后的用户信息和token
   */
  @Public()
  @Post('login')
  async login(
    @Body('username') username: string,
    @Body('password') password: string,
  ) {
    const res = await this.authService.login(username, password);
    return success(res as Record<string, any>, '登录成功');
  }

  /**
   * 微信登录接口
   * @param code - 微信授权码
   * @returns 登录成功后的用户信息和token
   */
  @Public()
  @Post('wxlogin')
  async wxlogin(@Body('code') code: string) {
    const res = await this.authService.wxlogin(code);
    return success(res as Record<string, any>, '登录成功');
  }
}
